package com.chang;
import java.util.Arrays;
import java.util.Map;
import java.util.logging.Logger;
public class Simpler {
    private static Logger logger = Logger.getGlobal();
    private static Map<String, Object> case1 = Map.of("nums", new int[]{2, 7, 11, 15}, "target", 9);
    public static void main(String[] args) {
        logger.info(Arrays.toString(twoSum((int[]) case1.get("nums"), (int) case1.get("target"))));
    }
    /**
     * 给定一个整数数组 nums 和一个目标值 target，请你在该数组中找出和为目标值的那 两个 整数，并返回他们的数组下标。
     */
    private static int[] twoSum(final int[] nums, final int target) {
        logger.info("input" + Arrays.toString(nums) + ", target: " + target);
        for (int num : nums) {
            int dif = target - num;
            if (Arrays.stream(nums).anyMatch(n -> num != n && n == dif)) {
                logger.info("find result: " + num + "," + dif);
                return new int[]{Arrays.binarySearch(nums, num), Arrays.binarySearch(nums, dif)};
            }
        }
        return new int[]{};
    }
}
